import 'package:flutter/material.dart';
import 'package:flutter_enjoy/pages/home/components/my_nav_bar.dart';

// 公告数据类型 interface
class NoticeItem {
  final String title;
  final String content;
  final String time;
  NoticeItem({required this.title, required this.content, required this.time});
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  // ignore: library_private_types_in_public_api
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // 公告默认数据 @State
  final List<NoticeItem> _noticeList = [
    NoticeItem(
      title: '中秋、国庆温馨提示中秋、国庆温馨提示',
      content: '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
      time: '2024-09-22 15:00:00',
    ),
    NoticeItem(
      title: '国庆期间出行安全提示',
      content: '请广大业主合理安排出行时间，注意交通安全，遵守交通规则，文明出行。',
      time: '2024-09-20 09:30:00',
    ),
    NoticeItem(
      title: '小区电梯维护通知',
      content: '本周五上午9:00-12:00将对1号楼电梯进行例行维护，期间暂停使用，请提前做好安排。',
      time: '2024-09-18 17:00:00',
    ),
    NoticeItem(
      title: '停水通知',
      content: '因管道检修，9月25日8:00-18:00小区将临时停水，请提前储水。',
      time: '2024-09-17 14:20:00',
    ),
    NoticeItem(
      title: '垃圾分类温馨提示',
      content: '请大家自觉进行垃圾分类，共同维护美好家园环境。',
      time: '2024-09-15 10:00:00',
    ),
    NoticeItem(
      title: '业主大会通知',
      content: '本月28日晚7点将在小区多功能厅召开业主大会，欢迎各位业主积极参加。',
      time: '2024-09-12 16:30:00',
    ),
  ];

  @override
  Widget build(BuildContext context) => Scaffold(
        appBar: AppBar(
          title: const Text('享+社区'),
          centerTitle: true,
          backgroundColor: Colors.transparent,
          elevation: 0,
        ),
        backgroundColor: const Color(0xffe5e8f2),
        body: ListView(
          padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 0),
          children: [
            MyNavBar(),
            // 横幅图片
            ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child: Image.asset(
                'assets/images/banner@2x.jpg',
                fit: BoxFit.cover,
                height: 120,
                width: double.infinity,
              ),
            ),
            const SizedBox(height: 6),
            Container(
              height: 1,
              color: const Color(0xFFE0E0E0),
              margin: const EdgeInsets.only(bottom: 8),
            ),
            // 公告区块
            Padding(
              padding: const EdgeInsets.only(top: 6, bottom: 12),
              child: Row(
                children: [
                  Image.asset('assets/images/notice@2x.png',
                      width: 22, height: 22),
                  const SizedBox(width: 6),
                  const Text('社区',
                      style:
                          TextStyle(fontWeight: FontWeight.bold, fontSize: 18)),
                  const SizedBox(width: 2),
                  const Text('公告',
                      style: TextStyle(
                          color: Color(0xFFF5A623),
                          fontWeight: FontWeight.bold,
                          fontSize: 18)),
                ],
              ),
            ),
            ..._noticeList.map((item) => Padding(
                  padding: const EdgeInsets.only(bottom: 10),
                  child: Card(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(12)),
                    elevation: 2,
                    shadowColor: const Color(0x1A000000),
                    color: Colors.white,
                    child: Padding(
                      padding: const EdgeInsets.fromLTRB(14, 14, 14, 12),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            item.title,
                            style: const TextStyle(
                                fontWeight: FontWeight.bold, fontSize: 16),
                          ),
                          const SizedBox(height: 6),
                          Text(
                            item.content,
                            style: const TextStyle(
                                fontSize: 13, color: Color(0xFF999999)),
                          ),
                          const SizedBox(height: 12),
                          Text(
                            item.time,
                            style: const TextStyle(
                                fontSize: 11, color: Color(0xFFCCCCCC)),
                          ),
                        ],
                      ),
                    ),
                  ),
                )),
          ],
        ),
      );
}
